#ifndef SUBREACTOR_H
#define SUBREACTOR_H

#include "Common.h"

#include "Poco/Net/SocketReactor.h"
#include "Poco/SharedPtr.h"
#include "Poco/BasicEvent.h"

#include "readerwriterqueue/readerwriterqueue.h"
#include "concurrentqueue/concurrentqueue.h"

namespace Reactor
{
	class MOUDLE_API Session;
	struct MOUDLE_API DataPacket;
	struct MOUDLE_API SubReactorPrivate;
	class MOUDLE_API SubReactor : public Poco::Net::SocketReactor
	{
	public:
		SubReactor(moodycamel::ConcurrentQueue<std::shared_ptr<DataPacket>>& _packetQueue,
			std::condition_variable& _condi, const TryOp& _tryop);
		~SubReactor();

	public:
		void prepareStop(const void* _pSender);
		bool postPacket(const std::shared_ptr<DataPacket>& _packet);
		int socketCount() const;
		bool hasSocketHandlers();
		bool empty();
	protected:
		Poco::BasicEvent<void>& event();
		void notify();

	private:
		friend Session;
		std::shared_ptr<SubReactorPrivate> d;
	};
}
#endif